import $ajax from '@/utils/ajax'
import { useSystemStore } from '@/store/system'
import { AjaxRequestConfig } from 'uni-ajax'
export function $uniajax<T>(config: AjaxRequestConfig) : Promise<T> {
  return new Promise((resolve) => {
    if (!useSystemStore().isnetwork) {
      setTimeout(() => { // 开启定时器:uni-transition开启关闭之前若有异步代码，必须有最小延迟时间，不然关闭不了
        uni.showToast({ title: '暂无网络', icon: 'none' })
        resolve({
          msg: '暂无网络'
        } as unknown as T)
      }, 500)
      return
    }
    resolve($ajax(config))
  })
}
